/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = frmem.h                                            */
/*  NOTE      =                                                    */
/*  DATE      = 2014/09/29 by yaohl                                */
/*******************************************************************/

#ifndef __FRMEM_H_
#define __FRMEM_H_

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "frmem_cfg.h"

/* 内存检查 */
#if FR_MEM_LEAK_CHECK
    #include "frmem_chk.h"

/* 共享内存池 */
#elif FR_MEM_POOL
    #include "frmem_ncx.h"

/* 标准内存分配函数 */
#else
    int  __fr_mem_init(size_t s_size, const char *p_slab_name);
    void __fr_mem_stat(char **pp_outbuff);
    void __fr_mem_destroy(void);

    #define __frcomm_slab_init(x, y)    __fr_mem_init(x, y)
    #define __frcomm_slab_stat(x)       __fr_mem_stat(x)
    #define __frcomm_slab_destroy()     __fr_mem_destroy()

    void *__fr_memdup(const char *p_src, size_t s_size);

    #define __frcomm_malloc(x)       malloc(x)
    #define __frcomm_memdup(x,y)     __fr_memdup(x, y)
    #define __frcomm_strdup(x)       strdup(x)
    #define __frcomm_free(x)         free(x)
#endif


#if FR_MEM_STAT
    #include "frmem_stat.h"

    #define fr_slab_init(x, y)  __fr_memstat_init(x, y)
    #define fr_slab_stat(x)     __fr_memstat_info_all(x)
    #define fr_slab_all_used()     __fr_memstat_all_used()
    #define fr_slab_destroy()   __fr_memstat_destroy()

    #define frmalloc(x)       __fr_memstat_malloc(x)
    #define frstrdup(x)       __fr_memstat_strdup(x)
    #define frmemdup(x,y)     __fr_memstat_memdup(x, y)
    #define frfree(x)         __fr_memstat_free(x)
#else
    //不需要统计信息
    #define fr_slab_init(x, y)  __frcomm_slab_init(x, y)
    #define fr_slab_stat(x)     __frcomm_slab_stat(x)
    #define fr_slab_all_used()  0
    #define fr_slab_destroy()   __frcomm_slab_destroy()

    #define frmalloc(x)       __frcomm_malloc(x)
    #define frstrdup(x)       __frcomm_strdup(x)
    #define frmemdup(x,y)     __frcomm_memdup(x, y)
    #define frfree(x)         __frcomm_free(x)
#endif

#endif

